/**
  ******************************************************************************
  * @文件名           : app_tasks.c
  * @作者             : citunhk
  * @功能介绍         : 业务逻辑层文件
  *	@日期             : 2022.11.7
  ******************************************************************************
  * @注
  * 根据软件系统需求分析编写业务逻辑层代码，
  * 包括产品各个业务的操作流程（例如：数字量输入业务、模拟量输入、作为主站通讯业务等）。
  *
  ******************************************************************************
  *更改记录
  *日期 修改人 修改内容
  *
  *
  *
  ******************************************************************************
  */
/* Private includes ----------------------------------------------------------*/
#include "app_tasks.h"
#include "sys_data.h"
#include "dri_flash_sst.h"
#include "dri_HMI.h"
#include "dri_DigitalQuantity.h"
#include "dri_AnalogQuantity.h"
#include "bsp_pwm.h"
#include "dri_master.h"
#include "dri_slaver.h"
#include "dri_slaver_wiip_rtu.h"
#include "dri_slaver_smc_ascii.h"
#include "dri_slaver_smc_rtu.h"
#include "fml_alarm.h"
#include "dri_flash_sst.h"
#include "bsp_SPI.h"
#include "fml_pid.h"
#include "bsp_usart.h"
#include "bsp_IWDG.h"
#include "fml_compensate.h"
#include "dri_Pulse.h"
#include "fml_store.h"
#include <math.h>
#include <string.h>
#include "flash_test.h"
/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/
#define DEBUG 1
/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/


float pid = 0;
static void FUNC_Condition_To_DO(uint8_t candition, digitalOutType_t DO);
/**
* @函数名	Task1_HMIDATA
* @功能	    HMI服务程序  100ms
* @入口参数	无
* @返回值	无
*/
void Task1_HMIDATA(void)
{
	static uint16_t pHMI_New_Run = 0;  //运行新状态
	static uint16_t pHMI_Old_Run = 0;  //运行上次状态
	static uint16_t pHMI_New_Alarm = 0;  //报警复位新状态
	static uint16_t pHMI_Old_Alarm = 0;  //报警复位上次状态


	//设备状态更新
	rState_Chiller = (gState_Run & 0x01) | ((gES_Buzzer & 0x01)<<2) | ((gAlarmReset & 0x01)<<3) | ((gBuzzerFlag_Ctl & 0x01)<<4) | ((gLastState_Comp & 0x01)<<8) | ((gLastState_Pump & 0x01)<<9) | ((gState_Cool & 0x01)<<10) | ((gLastState_Heater & 0x01)<<11) | ((gEQUWaterin & 0x01)<<12);

    //温度单位转换
    if(UP.Para.Unit_Temp == 0)  //摄氏度-摄氏度
    {
		gPV_TTemp1 = gPV_Temp1;
		gPV_TTemp2 = gPV_Temp2;
	    gPV_TTempAbmi = gPV_TempAbmi;

    	gProgram_TSP = gProgram_SP;
    	gSV_TTemp1 = UP.Para.SV_Temp1;
    	gSV_TTemp2 = UP.Para.SV_Temp2;

    	gAlarm_HL_TTemp1 = UP.Para.Alarm_HL_Temp1;
		gAlarm_LL_TTemp1 = UP.Para.Alarm_LL_Temp1;
		gFLT_HL_TTemp1 = UP.Para.FLT_HL_Temp1;
		gFLT_LL_TTemp1 = UP.Para.FLT_LL_Temp1;
		gHL_TempSV1 = FP.Para.HL_TempSV1;
		gLL_TempSV1 = FP.Para.LL_TempSV1;
    }
    else  //摄氏度-华氏度
    {
		gPV_TTemp1 = 1.8 * gPV_Temp1 + 32;
		gPV_TTemp2 = 1.8 * gPV_Temp2 + 32;
	    gPV_TTempAbmi = 1.8 * gPV_TempAbmi + 32;

    	gProgram_TSP = 1.8 * gProgram_SP + 32;
    	gSV_TTemp1 = 1.8 * UP.Para.SV_Temp1 + 32;
    	gSV_TTemp2 = 1.8 * UP.Para.SV_Temp2 + 32;

    	gAlarm_HL_TTemp1 = 1.8 * UP.Para.Alarm_HL_Temp1 + 32;
		gAlarm_LL_TTemp1 = 1.8 * UP.Para.Alarm_LL_Temp1 + 32;
		gFLT_HL_TTemp1 = 1.8 * UP.Para.FLT_HL_Temp1 + 32;
		gFLT_LL_TTemp1 = 1.8 * UP.Para.FLT_LL_Temp1 + 32;
		gHL_TempSV1 = 1.8 * FP.Para.HL_TempSV1 + 32;
		gLL_TempSV1 = 1.8 * FP.Para.LL_TempSV1 + 32;
    }

    //流量单位转换
    if(UP.Para.Unit_Flow == 0)  //LPM-LPM
    {
    	gPV_TFlow = gPV_Flow;

    	gSV_TFlow = UP.Para.SV_Flow;

    	gAlarm_LL_TFlow = UP.Para.Alarm_LL_Flow;
    }
    else  //LPM-TPH
    {
    	gPV_TFlow = gPV_Flow * 0.06;

    	gSV_TFlow = UP.Para.SV_Flow * 0.06;

    	gAlarm_LL_TFlow = UP.Para.Alarm_LL_Flow * 0.06;
    }

    //压力单位转换
    if(UP.Para.Unit_Press == 0)  //kPa-kPa
    {
    	gPV_TPress_Out = gPV_Press_Out;
    	gPV_TPress_In = gPV_Press_In;

    	gSV_TPress = UP.Para.SV_Press;

    	gAlarm_HL_TPress = UP.Para.Alarm_HL_Press;
    	gAlarm_LL_TPress = UP.Para.Alarm_LL_Press;
    }
    else  //kPa-psi
    {
    	gPV_TPress_Out = 0.1450377 * gPV_Press_Out;
    	gPV_TPress_In = 0.1450377 * gPV_Press_In;

    	gSV_TPress = 0.1450377 * UP.Para.SV_Press;

    	gAlarm_HL_TPress = 0.1450377 * UP.Para.Alarm_HL_Press;
    	gAlarm_LL_TPress = 0.1450377 * UP.Para.Alarm_LL_Press;
    }

	DRI_HMI_RX_Integration();/* HMI接收数据处理 */

	//设备状态解析
	pHMI_New_Run = rState_Chiller & 0x0001;  //运行状态
	if(pHMI_New_Run != pHMI_Old_Run)
	{
		gState_Run = pHMI_New_Run;
		pHMI_Old_Run = pHMI_New_Run;
	}

	gES_Buzzer = (rState_Chiller & 0x0004)>>2;  //报警消音

	pHMI_New_Alarm = (rState_Chiller & 0x0008)>>3;  //报警复位
    if(pHMI_New_Alarm != pHMI_Old_Alarm)
    {
    	gAlarmReset = pHMI_New_Alarm;
    	pHMI_Old_Alarm = pHMI_New_Alarm;
    }

    //报警复位
	if(gAlarmReset == 1)
	{
		gAlarmReset = 0;

//		gAlaFlag_LowLevel = 0;
//		gAlaFlag_FacLowTemp = 0;
//		gAlaFlag_FacHighTemp = 0;
		gAlaFlag_LowTemp = 0;
		gAlaFlag_HighTemp = 0;
		gAlaFlag_FacLowFlow = 0;
		gAlaFlag_FacInLowFlow = 0;
		gAlaFlag_LowFlow = 0;
		gAlaFlag_COWLowFlow = 0;
//		gAlaFlag_PumpMaint = 0;
//		gAlaFlag_CompMaint = 0;
//		gAlaFlag_FilterMaint = 0;
		gAlaFlag_RefHighPress = 0;
		gAlaFlag_RefLowPress = 0;
//		gAlaFlag_TempSensor1 = 0;
//		gAlaFlag_FlowSensor = 0;
//		gAlaFlag_Communication = 0;
		gAlaFlag_PressOutSensor = 0;
		gAlaFlag_HL_OutPress = 0;
		gAlaFlag_LL_OutPress = 0;
		rFlag_Comp = 0;
		gAlaFlag_PumpCom1 = 0;

		gAlaFlag_TempSensor_Tc1 = 0;
		gAlaFlag_TempSensor_Te1 = 0;
		gAlaFlag_TempSensor_To1 = 0;
		gAlaFlag_LL_Te1 = 0;
		gAlaFlag_HL_Te1 = 0;
		gAlaFlag_HL_To1 = 0;  //出气温度上限限值报警标志
		gAlaFlag_PressSensor_Te1 = 0;
		gAlaFlag_PressSensor_Tc1 = 0;
		gAlaFlag_RefNormalLowPress = 0;//氟压平衡低压报警

		if(FP.Para.Type_LL_Flow == 1)  //故障
		{
		  gAlaFlag_FacLowFlow1 = 0;
		}

		gSlaver_AlaFlag_Press1 = 0;
		gSlaver_AlaFlag_Press2 = 0;
		gSlaver_AlaFlag_PressSW2 = 0;

		rState_Alarm1 = 0;
		rState_Alarm2 = 0;
		rState_Alarm3 = 0;
		rState_Alarm4 = 0;
		rState_Alarm5 = 0;
		gAlaFlag_FLT = 0;
		gAlaFlag_CompFLT = 0;
		gAlaFlag_HeaterFLT = 0;
	}

}

/**
* @函数名	Task2
* @功能	    模拟量采集 看门狗喂狗 设备计时  100ms
* @入口参数	无
* @返回值	无
*/
void Task2_PeriodicUpdata(void)
{
	static uint8_t pFlag_AD = 0;  //AD采集标志
	static uint8_t pFlag_1s = 1;  //1秒钟周期标志
//	static uint16_t pFlag_6min = 1;  //6分钟周期标志

	if(++pFlag_1s > 1000 / task_structs[TASK_2].interval_time)
	{
		BSP_IWDG_ReloadCounter();  //喂狗  周期不能超过4.096秒
		DRI_EQU_SetFunState(LED_RUN,TOGGLE);  //运行灯闪烁
		pFlag_1s = 1;
	}

//	if(++pFlag_6min > 360000 / task_structs[TASK_2].interval_time)
//	{
//
//		pFlag_6min = 1;
//	}
	FML_Alarm_Update();  //报警更新

	DRI_Analog_In();  //获取AD值

	if(pFlag_AD == 3)
	{
		gPV_Temp1 = DRI_Read_Temp(1)/10;  //获取温度1  主温度
		gPV_Temp2 = FP.Para.ES_Temp2? DRI_Read_Temp(2)/10: NULL_VALUE;	//获取温度2  辅温度
		gPV_TempAbmi = FP.Para.ES_TempAmbi? DRI_Read_Temp(3)/10: NULL_VALUE;	//获取温度3  环境温度

		//获取流量  模拟量输入1
		if(FP.Para.ES_Flow == 1)
		{
			gPV_Flow = DRI_Read_Flow(1);  //获取流量  模拟量流量计
		}
		else if(FP.Para.ES_Flow == 2)
		{
			gPV_Flow = DRI_getFlowFromPulse();  //获取流量 脉冲流量计
		}
		else
		{
			gPV_Flow = 0;
		}
		gPV_Press_Out = FP.Para.ES_Press_Out? DRI_Read_Flow(2): 0;//获取出液压力  模拟量输入2
		gPV_Press_In = FP.Para.ES_Press_In? DRI_Read_Flow(3): 0;//获取回液压力  模拟量输入3
		gPV_DI = FP.Para.ES_DI? DRI_Read_Flow(4): 0;//获取水质电导率  模拟量输入4
	}
	else
	{
		if(pFlag_AD < 3)
		{
			pFlag_AD++;
		}
	}

}

/**
* @函数名	Task3
* @功能	    工艺编程  500ms
* @入口参数	无
* @返回值	无
*/
void Task3_ProcessProgram(void)
{
	static uint16_t pTempTime = 0;  //温度稳定计时
	static uint16_t pTimeCnt = 0;  //计时

	if(gState_Run == 1)  //启动冷水机
	{
		if(gProgram_State == 1)  //程序控温启动
		{
			if(gProgram_LastState == 1)  //上次程序控温启动
			{
				UP.Para.SV_Temp1 = gProgram_SP;  //更新目标温度

				if((gProgram_StableTime == 0) && (pTimeCnt > 9))  //程序控温倒计时
				{
					if(++gProgram_Step < 10)  //程序控温序号
					{
						pTimeCnt = 0;
						pTempTime = 0;
					}
					else  //完成一次完整程序控温
					{
						if(UP.Para.ES_Program_Cycle == 1)  //程序控温循环
						{
							gProgram_Step = 0;
							gProgram_SP = gProgram_SV_FirstRecord;  //第一段温度
							gProgram_Time_ThisStep = gProgram_Time_FirstStep;  //第一段时间
							pTempTime = 0;
						}
						else  //程序控温不循环
						{
							gProgram_State = 0;
						}
					}
				}
				if(gProgram_Time_ThisStep == 0)  //时间为0  开始下一次循环
				{
					if(UP.Para.ES_Program_Cycle == 1)  //程序控温循环
					{
						gProgram_Step = 0;
						gProgram_SP = gProgram_SV_FirstRecord;  //第一段温度
						gProgram_Time_ThisStep = gProgram_Time_FirstStep;  //第一段时间
						pTempTime = 0;
					}
					else  //程序控温不循环
					{
						gProgram_State = 0;
					}
				}
				if(pTempTime < 120000/task_structs[TASK_3].interval_time)  //温度稳定计时时间  2分钟
				{
					if(pTimeCnt < 10)
					{
						pTimeCnt++;
					}
					else
					{
						if(gProgram_Step == 0)
						{
						  gProgram_Time_FirstStep = gProgram_Time_ThisStep;
						}
					}

					if((fabs(gPV_Temp1 - UP.Para.SV_Temp1) <=1))  //温度稳定范围
					{
						if(++pTempTime > 120000/task_structs[TASK_3].interval_time)  //温度稳定计时时间增加  2分钟
						{
							gProgram_StableTime--;  //程序控温稳定倒计时
						}
					}
					else  //温度未稳定
					{
						gProgram_StableTime = gProgram_Time_ThisStep;
						pTempTime = 0;  //温度稳定计时清零
					}
				}
				else  //温度稳定
				{
					gProgram_StableTime--;  //程序控温倒计时
				}
			}
			else  //刚启动程序控温
			{
				gProgram_SV_Temp1Record = UP.Para.SV_Temp1;
				UP.Para.SV_Temp1 = gProgram_SP;
				gProgram_SV_FirstRecord = gProgram_SP;
				gProgram_StableTime = gProgram_Time_ThisStep;
				pTempTime = 0;
				gProgram_LastState = 1;
			}

		}
		else  //程序控温关闭
		{
			if(gProgram_LastState == 1)  //关闭程序控温
			{
				pTempTime = 0;
				pTimeCnt = 0;
				UP.Para.SV_Temp1 = gProgram_SV_Temp1Record;
				gProgram_Step = 0;
				gProgram_LastState = 0;
			}
		}
	}
	else  //设备关闭
	{
		if(gProgram_LastState == 1)
		{
			pTempTime = 0;
			pTimeCnt = 0;
			gProgram_State = 0;
			UP.Para.SV_Temp1 = gProgram_SV_Temp1Record;
			gProgram_Step = 0;
			gProgram_LastState = 0;
		}
	}
}

/**
* @函数名	Task4_ReturnLiquid
* @功能	    气吹排液  1000ms
* @入口参数	无
* @返回值	无
*/
void Task4_ReturnLiquid(void)
{
	static uint8_t pLastState_Return = 0;  //气吹回液当前启停状态

	if(gState_Return == 1)  //气吹回液功能打开状态
	{
		pLastState_Return = gState_Return;  //气吹回液功能状态更新

		if(gState_Run == 0)  //关机状态
		{
			if(gRunTime_RetunFluid++ < UP.Para.Time_RetunFluid)  //排液延时
			{
				DRI_EQU_SetFunState(RETURN_VALVE, TOGGLE);//排液
			}
			else  //排液结束
			{
				if(gRunTime_RetunAir++ < UP.Para.Time_RetunAir) //排空延时
				{
					DRI_EQU_SetFunState(RETURN_VALVE, ON);//排空
				}
				else  //气吹回液运行结束
				{
					gState_Return = 0;
				}
			}
		}
		else  //开机状态
		{
			gState_Return = 0;
		}
	}
	else  //气吹回液功能关闭状态
	{
		if(pLastState_Return == 1)  //关闭气吹回液状态
		{
			pLastState_Return = 0;
			gRunTime_RetunFluid = 0;
			gRunTime_RetunAir = 0;
			DRI_EQU_SetFunState(RETURN_VALVE, OFF); //关闭气吹电磁阀
		}
	}
}

/**
* @函数名	Task5_CheakAlarm
* @功能	    报警检测  100ms
* @入口参数	无
* @返回值	无
*/
void Task5_CheakAlarm(void)
{
	static uint8_t pCnt_Time1000ms = 0;
	static uint32_t pCnt_Time = 0;

	if(gAlarmTimeCnt < 1000)  //设备上电计时
	{
		gAlarmTimeCnt++;
	}

    if(gLastState_Pump == 1)  //水泵开机
    {
    	if(gTime_RunPump <= 9990)  //水泵开机计时
    	{
    		gTime_RunPump++;
    	}
    }
    else  //水泵关机
    {
    	gTime_RunPump = 0;
    }

    FML_Alarm_LowLevel();  //低液位报警检测
	FML_Alarm_LevelSensor();  //液位开关检测
	FML_Alarm_FacTemp(); //工厂温度报警检测

	FML_Alarm_Temp();  //用户温度报警检测
	FML_Alarm_FacCHWLowFlow();  //冷冻水低流量报警检测
	FML_Alarm_FacInLowFlow();  //内循环低流量开关报警检测
	FML_Alarm_FacCOWLowFlow();  //冷却水低流量报警检测
	FML_Alarm_FacLowFlow();  //工厂保护流量限值报警检测

	//流量限值检测
	if((UP.Para.ES_IO_Digital == 1) && (gEQUWaterin == OFF))
	{
		gAlaFlag_LowFlow = 0;
		gAlaFlag_HL_OutPress = 0;
		gAlaFlag_LL_OutPress = 0;
	}
	else
	{
		FML_Alarm_LowFlow();  //流量限值报警检测
		FML_Alarm_OutInPress();  //出液回液压力限值检测
	}

	FML_Alarm_Maint();  //设备维护报警
	FML_Alarm_OverFlow();  //溢流开关报警检测
	FML_Alarm_Press();  //氟路高低压报警检测
	FML_Alarm_DI();  //水质报警检测


	FML_Alarm_CHWFlowSensor();  //低流量开关传感器检测
	FML_Alarm_InFlowSensor();  //内循环低流量开关传感器检测
	FML_Alarm_PressSensor1();  //高压传感器  氟路1压力传感器检测
	FML_Alarm_PressSensor2();  //低压传感器  氟路2压力传感器检测

	FML_Alarm_SlaverLowPress();  //从机氟压限值报警检测
	FML_Alarm_SlaverHighPress();  //从机氟压高压开关报警检测

	if(gAlarmTimeCnt > 50)  //上电5S
	{
		FML_Alarm_TempSensor1();  //主温度传感器检测
		FML_Alarm_TempSensor2();  //辅温度传感器检测
		FML_Alarm_TempSensor3();  //环境温度传感器检测
		FML_Alarm_TempSensor_Tc();  //冷凝温度传感器检测
		FML_Alarm_TempSensor_Te();  //蒸发温度传感器检测
		FML_Alarm_TempSensor_To();//出气温度传感器检测
		FML_Alarm_PressSensor_Te();//蒸发压力传感器检测
		FML_Alarm_PressSensor_Tc();  //冷凝压力传感器检测
		FML_Alarm_FlowSensor();  //流量传感器检测
		FML_Alarm_DISensor();  //水质传感器检测
		FML_Alarm_PressOutSensor();  //出液压力传感器检测
		FML_Alarm_PressInSensor(); //回液压力传感器检测
	}

	FML_Alarm_Communication();  //通讯检测
	FML_Alarm_Tran();  //报警汇总

	//蜂鸣器
	if(gFlag_Buzzer == 3)  //蜂鸣器完成开机鸣叫
	{
		if(gES_Buzzer == 1)  //打开蜂鸣器
		{
			pCnt_Time = 0;
			if(gBuzzerFlag_Ctl == 1)  //有报警
			{
				if(++pCnt_Time1000ms > 1000/task_structs[TASK_5].interval_time)
				{
					pCnt_Time1000ms = 0;
					DRI_EQU_SetFunState(BUZZER1, TOGGLE);  //蜂鸣器状态翻转
				}
			}
			else  //无报警
			{
				DRI_EQU_SetFunState(BUZZER1, OFF);  //关闭蜂鸣器
			}
		}
		else  //关闭蜂鸣器
		{
			DRI_EQU_SetFunState(BUZZER1, OFF); //关闭蜂鸣器
			if(++pCnt_Time > 600000/task_structs[TASK_5].interval_time)
			{
				pCnt_Time = 0;
				gES_Buzzer = 1;  //打开蜂鸣器
			}
		}
	}
}

/**
* @函数名	Task6_FlowCtrl
* @功能	    流量控制  200ms
* @入口参数	无
* @返回值	无
*/
void Task6_FlowCtrl(void)
{
	uint16_t pFlowOut1 = 0;
//	uint16_t pFlowOut2 = 0;
	static uint16_t pFlowTime = 0;

	if((gState_Run == 1) && (gAlaFlag_FLT == 0))  //开机  无故障
	{
		gState_Pump = 1;

		if(gLastState_Pump == 0)  //水泵未打开
		{
			gLastState_Pump = 1;
			gTime_StopPump = 0;
			if(FP.Para.ES_FlowContr != 2)  //无变频器
			{
				DRI_EQU_SetFunState(PUMP, ON); //打开水泵
			}
		}
	}
	else  //停机状态  故障
	{
		gState_Run = 0;
		gState_Pump = 0;
		if((gState_Run == 0) || (gAlaFlag_FLT == 1) )
		{
			if(gLastState_Pump == 1)  //水泵已打开
			{
				if(++gTime_StopPump > UP.Para.Time_StopDelayPump * (gAlaFlag_TempSensor1? 150: 5))  //延时关闭水泵  600s/20s
				{
					gLastState_Pump = 0;
					if(FP.Para.ES_FlowContr != 2)  //无变频器
					{
						DRI_EQU_SetFunState(PUMP, OFF);  //关闭水泵
					}
				}
			}
		}
	}

	if(((gState_Pump) || (gLastState_Pump == 1)) && (FP.Para.ES_FlowContr == 1))  //模拟量
	{
		if(++pFlowTime > 4)
		{
			if(UP.Para.Type_FlowContr == 1)  //控压
			{
				pFlowOut1 = FML_PID_PressOperation()*4095/100;
			}
			else if(UP.Para.Type_FlowContr == 0)  //控流
			{
				pFlowOut1 = FML_PID_FlowOperation()*4095/100;
			}
			DRI_Analog_Output(ONE_AOUT,pFlowOut1);
			pFlowTime = 0;
		}
	}

}

/**
* @函数名	Task7_TempCtrl
* @功能	    温度控制  100ms
* @入口参数	无
* @返回值	无
*/
void Task7_TempCtrl(void)
{
	static float pPIDData = 0;  //PID累计
	static uint16_t pTime_StopComp = 0;  //压缩机停机延时计时
	if(gState_Run == 1)  //开机
	{
		if(FP.Para.Tepy_Comp == 0)  //启停式
		{
			if(FP.Para.Type_CompNumber == 0)  //单机头模式
			{
				if(gPV_Temp1 < (UP.Para.SV_Temp1 - FP.Para.D_Value_CT))
				{
					gState_Comp = 0;
					gState_Cool = 0;
				}
				else
				{
					if(gPV_Temp1 > (UP.Para.SV_Temp1 + FP.Para.D_Value_CT))
					{
						gState_Comp = 1;
						gState_Cool = 2;
					}
				}
			}
			else if(FP.Para.Type_CompNumber == 1)  //双机头模式
			{
				if(++gTime_PID % 10 == 0)  //1S
				{
					pPIDData += FML_PID_TempOperation();

					if(gTime_PID > 99)  //10S
					{
						gValue_PID = pPIDData/10;  //PID计算
						if(gValue_PID < 5)  //小信号切除
						{
							gValue_PID = 0;
						}
						else if(gValue_PID > 95)
						{
							gValue_PID = 100;
						}
						pPIDData = 0;
						gTime_PID = 0;
					}
				}

				if((gValue_PID > 0.0)  && (gValue_PID <= 30))  //打开2个压缩机
				{
					gState_Comp = 1;
					gState_Comp2 = 1;
					gState_Cool = 2;
				}
				else if((gValue_PID > 30)  && (gValue_PID <= 60))  //打开1个压缩机
				{
					if((gState_Comp == 0) && (gState_Comp2 == 0))  //需要启动1个压缩机
					{
						if(gRunTime_Comp > gRunTime_Comp2)  //启动第2个压缩机
						{
							gState_Comp2 = 1;
						}
						else  //启动第1个压缩机
						{
							gState_Comp = 1;
						}
					}
					else if((gState_Comp == 1) && (gState_Comp2 == 1))  //需要关闭1个压缩机
					{
						if(gRunTime_Comp >= gRunTime_Comp2)  //关闭第1个压缩机
						{
							gState_Comp = 0;
						}
						else  //关闭第2个压缩机
						{
							gState_Comp2 = 0;
						}
					}
					gState_Cool = 2;
				}
				else if((gValue_PID > 60)  && (gValue_PID <= 100))  //关闭所有压缩机
				{
					gState_Comp = 0;
					gState_Comp2 = 0;
					gState_Cool = 0;
				}
			}
		}
		else  //PID式
		{
			if(FP.Para.Type_CompNumber == 0)  //单机头模式
			{
				gState_Comp = 1;
				if(++gTime_PID % 10 == 0)  //1S
				{
					pPIDData += FML_PID_TempOperation();

					if(gTime_PID > 99)  //10S
					{
						gValue_PID = pPIDData/10;  //PID计算
						if(gValue_PID < 5)  //小信号切除
						{
							gValue_PID = 0;
						}
						else if(gValue_PID > 95)
						{
							gValue_PID = 100;
						}
						pPIDData = 0;
						gTime_PID = 0;
					}
				}

				if(gTime_PID < gValue_PID)  //加热
				{
					gState_Cool = 0;
					gState_CoolValve = 0;
					if(FP.Para.Type_Heater == 0)  //全加热
					{
						gState_Heater = 1;
					}
				}
				else  //制冷
				{
					gState_Cool = 2;
					gState_CoolValve = 1;
					if(FP.Para.Type_Heater == 0)  //全加热
					{
						gState_Heater = 0;
					}
				}
			}
		}
		if(FP.Para.Type_Heater == 1)  //预加热
		{
			if(gPV_Temp1 < (UP.Para.SV_Temp1 - gSV_Temp1DIF1))
			{
				gState_Heater = 1;
			}
			else
			{
				if(gPV_Temp1 > (UP.Para.SV_Temp1 - gSV_Temp1DIF2))
				{
					gState_Heater = 0;
				}
			}
		}
	}
	else
	{
		gState_Comp = 0;
		gState_Heater = 0;
		gState_CoolValve = 0;
		gState_Cool = 0;
	}

	if((gState_Cool == 2) && (gLastState_Comp == 1))
	{
		gState_Cool = 1;  //制冷状态更新  2不显示  只有1的时候显示制冷图标
	}

	if(gAlaFlag_CompFLT == 1)  //压缩机停机
	{
		gState_Comp = 0;
	}
	if(gLastState_Comp == 0)  //压缩机未运行
	{
		if(pTime_StopComp <= FP.Para.Time_RunDelayComp)  //压缩机停机计时
		{
			pTime_StopComp++;
		}
//		else
//		{
//			pTime_StopComp = FP.Para.Time_RunDelayComp + 1;
//		    gTime_StopComp = pTime_StopComp;
//		}
		if(gState_Comp == 1)  //启动压缩机
		{
			if(gTime_StopComp <= FP.Para.Time_RunDelayComp)
			{
				gTime_StopComp = pTime_StopComp;  //延时更新  开压机给真实值
			}
			if(gTime_StopComp > FP.Para.Time_RunDelayComp)  //达到停机延时时间
			{
				if(gFlag_EEVInitOver1 == 1)  //电子膨胀阀初始化已完成
				{
					if( gSlaver_Press1 < FP.Para.LL_PassPV_Te1_nm)
					{
						gAlaFlag_RefNormalLowPress = 1;//氟压平衡低压报警
					}
					else
					{
						DRI_EQU_SetFunState(COMP, ON);//压缩机启动
						gLastState_Comp = 1;
					}
				}
			}
		}
		else  //未启动压缩机
		{
			gTime_StopComp = FP.Para.Time_RunDelayComp;  //延时更新  未开压机延时为0显示不显示
		}
	}
	else  //压缩机运行中
	{
		if(gState_Comp == 0)  //关闭压缩机
		{
			DRI_EQU_SetFunState(COMP, OFF);//压缩机停止
			pTime_StopComp = 0;
			gLastState_Comp = 0;
		}

		if(gFlag_EEVInitOver1 == 0)  //电子膨胀阀没有完成初始化
		{
			DRI_EQU_SetFunState(COMP, OFF);//压缩机停止
			pTime_StopComp = 0;
			gState_Comp = 0;
			gLastState_Comp = 0;
		}

	}

	if((gAlaFlag_HeaterFLT == 0) && (gState_Heater == 1))
	{
		DRI_EQU_SetFunState(HEAT, ON);//加热器启动
	}
	else
	{
		DRI_EQU_SetFunState(HEAT, OFF); //加热器停止
	}

	if(gLastState_Comp != 1)  //压缩机未运行
	{
		gState_CoolValve = 1;  //打开制冷阀
	}
	if(gState_CoolValve == 1)  //启动制冷阀
	{
		DRI_EQU_SetFunState(RE_VALVE, ON);  //制冷阀开启
	}
	else  //未启动制冷阀
	{
		DRI_EQU_SetFunState(RE_VALVE, OFF);  //制冷阀停止
	}


}

/**
* @函数名	Task8
* @功能	    辅助阀控制  1000ms
* @入口参数	无
* @返回值	无
*/
void Task8_AuxiliaryValve(void)
{
	if(gState_Run == 1)  //设备开机 todo:应改为判断压缩机的某种状态
	{
		/* 高温辅助制冷阀控制 */
		if(gPV_Temp1 > FP.Para.SV_Temp_OpenHighValve)
		{
			DRI_EQU_SetFunState(HIGH_TEMP_VALVE, ON);//高温制冷阀打开
		}
		else if(gPV_Temp1 < FP.Para.SV_Temp_CloseHighValve)
		{
			DRI_EQU_SetFunState(HIGH_TEMP_VALVE, OFF); //高温制冷阀关闭
		}
		/* 低温辅助制冷阀控制 */
		if(gPV_Temp1 < FP.Para.SV_Temp_OpenLowValve)
		{
			DRI_EQU_SetFunState(LOW_TEMP_VALVE, ON);  //低温制冷阀打开
		}
		else if(gPV_Temp1 > FP.Para.SV_Temp_CloseLowValve)
		{
			DRI_EQU_SetFunState(LOW_TEMP_VALVE, OFF);  //低温制冷阀关闭
		}
	}
	else  //设备关机
	{
		DRI_EQU_SetFunState(HIGH_TEMP_VALVE, OFF); //高温制冷阀关闭
		DRI_EQU_SetFunState(LOW_TEMP_VALVE, OFF);  //低温制冷阀关闭
	}
}

/**
* @函数名	Task9_CommSlave
* @功能	    RS485从机服务程序  100ms
* @入口参数	无
* @返回值	无
*/
void Task9_CommSlave(void)
{
	static uint16_t pRS485_Speed_Mode = 0;  //默认9600
	static uint16_t pRS485_Com_Mode = 0;  //默认WIIP协议

	//更新串口模式
	if(FP.Para.Com_Mode != pRS485_Com_Mode)
	{
		pRS485_Com_Mode = FP.Para.Com_Mode;
		DRI_USART3_Config_Switch(FP.Para.Com_Mode, UP.Para.RS485_Speed? 19200: 9600);
	}

	//更新串口波特率
	if(UP.Para.RS485_Speed != pRS485_Speed_Mode)
	{
		pRS485_Speed_Mode = UP.Para.RS485_Speed;  //更新模式标志
		DRI_USART3_BaudRate(UP.Para.RS485_Speed);  //设置串口波特率
	}

	if(UP.Para.Type_Communication == 1)   //打开通讯
	{
		//通讯异常检测
		if(gSlaver_State < 50)  //5秒
		{
		    gSlaver_State++;
		    UP.Para.RS485_State = 0;
		    gSlaver_Communication_ERR = 0;
		}
		else
		{
		    UP.Para.RS485_State = 1;
		    gSlaver_Communication_ERR = 1;
		}


		DRI_ModbusRTU_Slaver_RX_Process();

	}
	else  //关闭通讯
	{
		gSlaver_State = 0;
		UP.Para.RS485_State = 0;
		gSlaver_Communication_ERR = 0;
	}
}

/**
* @函数名	Task10
* @功能	    开机自检  100ms
* @入口参数	无
* @返回值	无
*/
void Task10_CheakSelf(void)
{
	static uint16_t pCnt_Start = 0;  //启动模式  自动  上电后延时
	static uint16_t pCnt_Buzzer = 0;  //蜂鸣器鸣叫延时
	static uint8_t pFlag_Start = 0;  //启动模式运行标志位
	static uint8_t pFlag_Buzzer = 0;  //蜂鸣器鸣叫标志位
	static uint8_t pFlag_Init = 0;  //参数初始化标志位

	//蜂鸣器开机鸣叫
	if(pFlag_Buzzer == 0)  //未进行过一次
	{
		if(++pCnt_Buzzer < 1000/task_structs[TASK_10].interval_time)
		{
			DRI_EQU_SetFunState(BUZZER1, ON);  //打开蜂鸣器
		}
		else
		{
			DRI_EQU_SetFunState(BUZZER1, OFF); //关闭蜂鸣器
			pFlag_Buzzer = 1;
#if(DEBUG==0)
			gFlag_Buzzer = 1;
#endif
		}
	}
	if(gLoading >= 99)
	{
		gLoading = 100;  //进度条
	}
	//参数初始化
	if(pFlag_Init == 2)
	{
		gVersion = 212;  //版本号
		DRI_Flash_Init();  //从存储中读取参数
		DRI_KB_Init();  //计算温度转换KB值
		gRunTime_Pump = FP.Para.RunTime_Pump_Save/10;  //水泵
		gRunTime_Comp = FP.Para.RunTime_Comp_Save/10;  //压缩机1
		gRunTime_Comp2 = FP.Para.RunTime_Comp2_Save/10;  //压缩机2
		gRunTime_Filter = FP.Para.RunTime_Filter_Save/10;  //过滤器
		pFlag_Init = 3;
	}

	//启动模式
	if((pFlag_Init == 3)&&(pFlag_Start == 0))  //未运行过一次
	{
		if(UP.Para.Type_Start == 1)
		{
			if(++pCnt_Start > 10000/task_structs[TASK_10].interval_time)  //上电自启动模式 前10s无动作
			{
				gState_Run = 1;  //开机
				pCnt_Start = 0;
				pFlag_Start = 1;
			}
		}
		else
		{
			pFlag_Start = 1;
		}
	}
	else
	{
		if(pFlag_Init < 3)
		{
			pFlag_Init++;
		}
	}

	if((pFlag_Start == 1) && (pFlag_Buzzer == 1) && (pFlag_Init == 3) && (gLoading == 100))  //所有功能执行完
	{
		task_structs[TASK_10].enable_flag = 0;  //关闭此任务
	}
}

/**
* @函数名	Task11
* @功能	    flash读写操作  100ms
* @入口参数	无
* @返回值	无
*/
void Task11_FlashOperation(void)
{
//	if(gSTATE_TempCalibration)
//	{
//		DRI_Calibration_AD();  //AD校准
//	}
//	//用户参数恢复出厂
//	if(gRestoryUP == 1)
//	{
//		gRestoryUP = 0;
//		DRI_Flash_ReadBuffer(&UP.flashBuff[0], ADDR_USER_SAVE, 500);//读取用户参数到buff中
//		DRI_Flash_ReadBuffer(&PID.Box[0], ADDR_PID_SAVE, 1000);//读取PID参数到buff中
//
//		DRI_Flash_Erase_4KByte(ADDR_USER_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&UP.flashBuff[0], ADDR_USER_PARA, 500);//写入用户初值到buff中
//
//		DRI_Flash_Erase_4KByte(ADDR_PID_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(PID.Box, ADDR_PID_PARA, sizeof(PID.Box));//写入用户初值到buff中
//	}
//
//	//用户参数保存
//	if(gSaveUP == 1)
//	{
//		gSaveUP = 0;
//
//		DRI_Flash_Erase_4KByte(ADDR_USER_SAVE);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&UP.flashBuff[0], ADDR_USER_SAVE, 500);//写入用户初值到buff中
//
//		DRI_Flash_Erase_4KByte(ADDR_PID_SAVE);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(PID.Box, ADDR_PID_SAVE, sizeof(PID.Box));//写入用户初值到buff中
//	}
//
//	//系统参数恢复出厂
//	if(gRestoryFP == 1)
//	{
//		gRestoryFP = 0;
//		DRI_Flash_ReadBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//读取系统参数到buff中
//	}
//
//	//系统参数保存
//	if(gSaveFP == 1)
//	{
//		gSaveFP = 0;
//
//		DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//	}
//	//设备运行计时
//	if(gMaintFlag_Reset == 1)  //设备维护复位
//	{
//		UP.Para.RunTime_Pump = 0;  //水泵
//		UP.Para.RunTime_Comp = 0;  //压机1
//		UP.Para.RunTime_Comp2 = 0;  //压机2
//		UP.Para.RunTime_Filter = 0;  //过滤器
//		DRI_Flash_Erase_4KByte(ADDR_USER_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&UP.flashBuff[0], ADDR_USER_PARA, 500);//写入系统参数初值到buff中
//		gMaintFlag_Reset = 0;
//	}
//
//	if(gState_Pump == 1)  //水泵运行中
//	{
//		static uint16_t Pump_RunTime = 1;
//		if(++Pump_RunTime > 360000/task_structs[TASK_11].interval_time)  // 360000毫秒
//		{
//			FP.Para.RunTime_Pump_Save++;  //6分钟存一次
//			DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//			DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//			gRunTime_Pump = FP.Para.RunTime_Pump_Save/10;  //小时
//			Pump_RunTime = 0;
//		}
//	}
//	if(gState_Comp == 1)  //压缩机1运行中
//	{
//		static uint16_t Comp1_RunTime = 1;
//		if(++Comp1_RunTime > 360000/task_structs[TASK_11].interval_time)  // 360000毫秒
//		{
//			FP.Para.RunTime_Comp_Save++;  //6分钟存一次
//			DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//			DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//			gRunTime_Comp = FP.Para.RunTime_Comp_Save/10;  //小时
//			Comp1_RunTime = 1;
//		}
//	}
//	if(gState_Comp2 == 1)  //压缩机2运行中
//	{
//		static uint16_t Comp2_RunTime = 1;
//		if(++Comp2_RunTime > 360000/task_structs[TASK_11].interval_time)  // 360000毫秒
//		{
//			FP.Para.RunTime_Comp2_Save++;  //6分钟存一次
//			DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//			DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//			gRunTime_Comp2 = FP.Para.RunTime_Comp2_Save/10;  //小时
//			Comp2_RunTime = 1;
//		}
//	}
//	if((gState_Comp == 1) || (gState_Comp2 == 1))  //过滤器运行中
//	{
//		static uint16_t Filter_RunTime = 1;
//		if(++Filter_RunTime > 360000/task_structs[TASK_11].interval_time)  // 360000毫秒
//		{
//			FP.Para.RunTime_Filter_Save++;
//			DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//			DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//			gRunTime_Filter = FP.Para.RunTime_Filter_Save/10;  //小时
//			Filter_RunTime = 1;
//		}
//	}
//	//冷水机计时
//	if(gState_Run == 1)  //设备运行中
//	{
//		static uint16_t Chiller_RunTime = 1;
//		if(++Chiller_RunTime> 360000/task_structs[TASK_11].interval_time)  //6分钟
//		{
//			FP.Para.RunTime_Chiller_Save++;  //6分钟存一次
//			DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//			DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//			FP.Para.RunTime_Chiller = FP.Para.RunTime_Chiller_Save/10;   //小时
//			Chiller_RunTime = 1;
//		}
//	}
//	if((rMaintFlag_Reset & 0x01) == 1)  //水泵运行时长复位
//	{
//		FP.Para.RunTime_Pump_Save = 0;
//		DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//		gRunTime_Pump = FP.Para.RunTime_Pump_Save/10;  //小时
//		rMaintFlag_Reset = 0;
//	}
//	else if((rMaintFlag_Reset & 0x02) == 2)  //压机1运行时长复位
//	{
//		FP.Para.RunTime_Comp_Save = 0;
//		DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//		gRunTime_Comp = FP.Para.RunTime_Comp_Save/10;  //小时
//		rMaintFlag_Reset = 0;
//	}
//	else if((rMaintFlag_Reset & 0x04) == 4)  //过滤器运行时长复位
//	{
//		FP.Para.RunTime_Filter_Save = 0;
//		DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//		gRunTime_Filter = FP.Para.RunTime_Filter_Save/10;  //小时
//		rMaintFlag_Reset = 0;
//	}
//	else if((rMaintFlag_Reset & 0x08) == 8)  //压机2运行时长复位
//	{
//		FP.Para.RunTime_Comp2_Save = 0;
//		DRI_Flash_Erase_4KByte(ADDR_SYSTEAM_PARA);//写入前擦除
//		DRI_Flash_AAI_WriteBuffer(&FP.flashBuff[0], ADDR_SYSTEAM_PARA, 500);//写入系统参数初值到buff中
//		gRunTime_Filter = FP.Para.RunTime_Comp2_Save/10;  //小时
//		rMaintFlag_Reset = 0;
//	}
//	else
//	{
//		rMaintFlag_Reset = 0;
//	}
}

/**
* @函数名	Task12_TempOffset
* @功能	    温度补偿  1000ms
* @入口参数	无
* @返回值	无
*/
void Task12_TempOffset(void)
{
	float pTemp_Dif_Ave = 0;  //差值绝对值平均值
	float pTemp_Dif_Dif_Ave = 0;  //差值差值绝对值平均值
	static float pTemp_Dif = 0;  //温度差值
	static float pLsatTemp_Dif = 0;  //上次温度差值
	static uint8_t pCnt_Time10S = 0;  //时间计数
	static uint8_t pFlag_Dif = 0;  //第一次计算差值标志
	static uint8_t pFlag_Temp = 0;  //第一次进入标志
	static uint8_t pCnt_Temp = 0;  //数组计数
	static float pTemp_Difference[50] = {0};  //温度差值
	static float pTemp_Difference_Difference[50] = {0};  //温度差值差值绝对值
	static tempState_t pLastState_Temp = 0;  //温度补偿温度状态

	//温度补偿
	if(UP.Para.Type_Compensate == 0)  //手动输入
	{
		gSV_Temp1 = UP.Para.SV_Temp1 + UP.Para.SV_Compensate;
	}
	else  //自动模式
	{
		if(pFlag_Temp == 0)  //第一次进入
		{
			pFlag_Temp = 1;
			gSV_Temp1 = UP.Para.SV_Temp1 + UP.Para.SV_AutoCompensate;  //开机目标温度
		}

		if(++pCnt_Time10S > 10000/task_structs[TASK_12].interval_time)  //10S
		{
			//计算主温度设定温度与辅温度的差值绝对值
			pLsatTemp_Dif = pTemp_Dif;  //上次差值更新
			pTemp_Dif = UP.Para.SV_Temp1 - gPV_Temp2;  //差值更新
			pTemp_Difference[pCnt_Temp] = fabs(pTemp_Dif);  //偏差绝对值
			if(pFlag_Dif > 0)
			{
				pTemp_Difference_Difference[pCnt_Temp-1] = fabs(pTemp_Dif - pLsatTemp_Dif);  //温度差值差值的绝对值
			}
			pCnt_Temp++;
			pFlag_Dif = 1;  //第一次计算差值标志

			if(pCnt_Temp >= UP.Para.SV_TimeCompensate)  //计算20次偏差
			{
				pCnt_Temp = 0;

				//偏差绝对值平均值
				pTemp_Dif_Ave = FML_MedianFilter(pTemp_Difference,UP.Para.SV_TimeCompensate);

				//偏差偏差绝对值平均值
				pTemp_Dif_Dif_Ave = FML_MedianFilter(pTemp_Difference_Difference,(UP.Para.SV_TimeCompensate-1));

				if(pTemp_Dif_Dif_Ave <= UP.Para.SV_AccuracyCompensate)  //主温度设定与辅温度误差减小  趋于稳定
				{
					if(pLastState_Temp == DYNAMIC)  //动态
					{
						UP.Para.SV_AutoCompensate = gPV_Temp1 - gPV_Temp2;  //自动温度补偿温度值计算
						gSV_Temp1 = UP.Para.SV_Temp1 + UP.Para.SV_AutoCompensate;  //更新冷水机实际目标温度
						pLastState_Temp = STEADY;  //稳态
					}
				}
				else  //不稳定
				{
					if(pLastState_Temp == STEADY)  //稳态
					{
						pLastState_Temp = DYNAMIC;  //动态
					}
				}

				if((pLastState_Temp == STEADY) && (pTemp_Dif_Ave >0.1))  //稳态  温度偏差变大
				{
					UP.Para.SV_AutoCompensate = gPV_Temp1 - gPV_Temp2;  //自动温度补偿温度值计算
					gSV_Temp1 = UP.Para.SV_Temp1 + UP.Para.SV_AutoCompensate;  //更新冷水机实际目标温度
					pLastState_Temp = DYNAMIC;  //动态
				}
			}
			pCnt_Time10S = 0;
		}
	}
}

/**
* @函数名	Task13
* @功能	    数字量输入输出配置  1000ms
* @入口参数	无
* @返回值	无
*/
void Task13_ConfigDIO(void)
{
//	static equState_t pState_New_Run = OFF;  //冷水机运行新状态
//	static equState_t pState_Old_Run = OFF;  //冷水机运行上次状态
//	static equState_t pState_New_Reset = OFF;  //冷水机报警复位新状态
//	static equState_t pState_Old_Reset = OFF;  //冷水机报警复位上次状态
//	static equState_t pState_New_Switch = OFF;  //冷水机外部保护开关新状态
//	static equState_t pState_Old_Switch = OFF;  //冷水机外部保护开关新状态
//	static equState_t pState_New_Waterin = OFF;  //水路电磁阀输入新状态
//	static equState_t pState_Old_Waterin = OFF;  //水路电磁阀输入上次状态
//	static equState_t pState_New_Stop = OFF;  //急停开关新状态
//	static equState_t pState_Old_Stop = OFF;  //急停开关上次状态
//	static uint8_t pFlag_FP_IN5 = 0;  //工厂数字量输入1-DIN5消除抖动标志
//	static uint8_t pFlag_UP_IN6 = 0;  //客户数字量输入1-DIN6消除抖动标志
//	static uint8_t pFlag_UP_IN7 = 0;  //客户数字量输入2-DIN7消除抖动标志

//	uint8_t pFlag_KA1 = 0;  //KA1输出标志
//	uint8_t pFlag_KA2 = 0;  //KA2输出标志
//	uint16_t i = 0;

	//用户数字量输入输出配置相关
	if(UP.Para.ES_IO_Digital == 1)  //用户数字量输入输出使能
	{
		DRI_EQU_UserConfig_Output1();	/* 用户输出接口1配置*/

		DRI_EQU_UserConfig_Input1();	/* 用户输入接口1配置*/

		if(FP.Para.Digital_Out2_Definition == 0)  //数字量输出2-KA2工厂开放给用户
		{
			DRI_EQU_UserConfig_Output2();	/* 用户输出接口2配置*/
		}

		if(FP.Para.Digital_In4_Definition == 0)  //数字量输入7-IN7工厂开放给用户
		{
			DRI_EQU_UserConfig_Input2();	/* 用户输入接口2配置*/
		}
	}

	//工厂数字量输入1-DIN4 信号定义
	DRI_EQU_FactoryConfig_Input1();

	//工厂数字量输入2-DIN5 信号定义
	DRI_EQU_FactoryConfig_Input2();

	//工厂数字量输入3-DIN2 信号定义
	DRI_EQU_FactoryConfig_Input3();

	//工厂数字量输入4-DIN7 信号定义
	DRI_EQU_FactoryConfig_Input4();

	//工厂数字量输出1-KA3 信号定义
	DRI_EQU_FactoryConfig_Output1();

	//工厂数字量输出2-KA2 信号定义
	DRI_EQU_FactoryConfig_Output2();
}

/**
* @函数名	Task14
* @功能	    主机控制  500ms
* @入口参数	无
* @返回值	无
*/
void Task14(void)
{
	static uint16_t pNow_Fre_Pump_MAX = 0;  //水泵运行最大频率
	static uint16_t pLast_Fre_Pump_MAX = 0;  //上一次水泵运行最大频率
	static uint16_t pNow_Fre_Pump_MIN = 0;  //水泵运行最小频率
	static uint16_t pLast_Fre_Pump_MIN = 0;  //上一次水泵运行最小频率
	static uint16_t pNow_SVPump = 0;  //水泵运行目标值
	static uint16_t pLast_SVPump = 0;  //上一次水泵运行目标值
	static uint16_t pNow_State_Pump = 0;  //水泵运行状态
	static uint16_t pLast_State_Pump = 0;  //上一次水泵运行状态

	static uint8_t pComp_Num1 = 0;  //水泵06通讯指令序号

	static uint8_t pCnt_Time = 0;  //通讯相关  时间计数
	static uint16_t pPressTime = 0;  //压力相关  时间计数
	static uint16_t pPressTime1 = 0;  //压力相关  时间计数1
	static uint16_t pCnt_20S = 0;  //20S计时延时

	static float pPIDOut = 0;  //PID计算值
	static float pPIDOut1 = 0;  //PID计算值1

	static uint8_t pFlag = 0;

	DRI_Master_RX_Integration();

	if(FP.Para.ES_FlowContr == 2)  //RS485
	{
		//数据更新
        if(gFlag_Pump_Fre == 0)
        {
			pNow_Fre_Pump_MAX = FP.Para.Fre_Pump_MAX*10;  //DF800
			pNow_Fre_Pump_MIN = FP.Para.Fre_Pump_MIN*10;  //DF800
        }
        else if(gFlag_Pump_Fre == 1)
        {
			pNow_Fre_Pump_MAX = FP.Para.Fre_Pump_MAX*100;  //DF900
			pNow_Fre_Pump_MIN = FP.Para.Fre_Pump_MIN*100;  //DF900
        }

		if(gLastState_Pump == 1)  //水泵打开
		{
			if(gAlaFlag_EStop == 1)  //急停保护  水泵控制任务关闭  强行关闭
			{
				gLastState_Pump = 0;
			}

			if(pCnt_20S < 200)
			{
				pCnt_20S++;
			}

			if(pCnt_20S < 19)  //10S
			{
				if(pFlag == 0)
				{
					if(gFlag_Pump_Fre == 0)
					{
						gSV_Comp = FP.Para.Fre_Pump_MIN*10;  //DF800
						pNow_SVPump = gSV_Comp;
					}
					else if(gFlag_Pump_Fre == 1)
					{
						gSV_Comp = FP.Para.Fre_Pump_MIN*100/FP.Para.Fre_Pump_MAX*100;  //DF900
						pNow_SVPump = gSV_Comp;
					}
				}
			}
			else if((fabs(UP.Para.SV_Press - gPV_Press_Out) > 10) && (gFlag_Pump_Fre == 0))  //DF800
			{
				if(pPressTime1%2 == 0)  //1S
				{
					if(UP.Para.Type_FlowContr == 1)  //控压
					{
						pPIDOut1 = pPIDOut1 + FML_PID_PressOperation();
					}
					else if(UP.Para.Type_FlowContr == 0)  //控流
					{
						pPIDOut1 = pPIDOut1 + FML_PID_FlowOperation();
					}

					//DF800
					gSV_Comp = pPIDOut1/10*(FP.Para.Fre_Pump_MAX - FP.Para.Fre_Pump_MIN) + FP.Para.Fre_Pump_MIN*10;
					if(gSV_Comp > FP.Para.Fre_Pump_MAX*10)
					{
						gSV_Comp = FP.Para.Fre_Pump_MAX*10;
					}
					else
					{
						if(gSV_Comp < FP.Para.Fre_Pump_MIN*10)
						{
							gSV_Comp = FP.Para.Fre_Pump_MIN*10;
						}
					}

					pNow_SVPump = gSV_Comp;

					pPIDOut1 = 0;
					pPressTime1 = 0;
				}

				pPressTime1++;
			}
			else if((fabs(UP.Para.SV_Press - gPV_Press_Out) > 1) && (gFlag_Pump_Fre == 1))  //DF900
			{
				if(pPressTime1%2 == 0)  //1S
				{
					if(UP.Para.Type_FlowContr == 1)  //控压
					{
						pPIDOut1 = pPIDOut1 + FML_PID_PressOperation();
					}
					else if(UP.Para.Type_FlowContr == 0)  //控流
					{
						pPIDOut1 = pPIDOut1 + FML_PID_FlowOperation();
					}

					//DF900
					gSV_Comp = pPIDOut1*100;  //DF900
					if(gSV_Comp > 10000)
					{
						gSV_Comp = 10000;
					}
					else
					{
						if(gSV_Comp < 100*FP.Para.Fre_Pump_MIN/FP.Para.Fre_Pump_MAX*100)
						{
							gSV_Comp = 100*FP.Para.Fre_Pump_MIN/FP.Para.Fre_Pump_MAX*100;
						}
					}

					pNow_SVPump = gSV_Comp;

					pPIDOut1 = 0;
					pPressTime1 = 0;
				}

				pPressTime1++;
			}
			else
			{
				if(pPressTime%2 == 0)  //1S
				{
					if(UP.Para.Type_FlowContr == 1)  //控压
					{
						pPIDOut = pPIDOut + FML_PID_PressOperation();
					}
					else if(UP.Para.Type_FlowContr == 0)  //控流
					{
						pPIDOut = pPIDOut + FML_PID_FlowOperation();
					}
				}

				if((++pPressTime > 19) && (gFlag_Pump_Fre == 0))  //10S  DF800
				{
					//DF800
					gSV_Comp = pPIDOut/100*(FP.Para.Fre_Pump_MAX - FP.Para.Fre_Pump_MIN) + FP.Para.Fre_Pump_MIN*10;
					if(gSV_Comp > FP.Para.Fre_Pump_MAX*10)
					{
						gSV_Comp = FP.Para.Fre_Pump_MAX*10;
					}
					else
					{
						if(gSV_Comp < FP.Para.Fre_Pump_MIN*10)
						{
							gSV_Comp = FP.Para.Fre_Pump_MIN*10;
						}
					}

					pNow_SVPump = gSV_Comp;

					pPIDOut = 0;
					pPressTime = 0;

					pFlag = 1;
				}
				else if((++pPressTime > 9) && (gFlag_Pump_Fre == 1))  //5S  DF900
				{
					//DF900
					pPIDOut = pPIDOut/5;
					gSV_Comp = pPIDOut*100;  //DF900
					if(gSV_Comp > 10000)
					{
						gSV_Comp = 10000;
					}
					else
					{
						if(gSV_Comp < 100*FP.Para.Fre_Pump_MIN/FP.Para.Fre_Pump_MAX*100)
						{
							gSV_Comp = 100*FP.Para.Fre_Pump_MIN/FP.Para.Fre_Pump_MAX*100;
						}
					}

					pNow_SVPump = gSV_Comp;

					pPIDOut = 0;
					pPressTime = 0;

					pFlag = 1;
				}
			}
		}
		else
		{
			pCnt_20S = 0;
		}


		pNow_State_Pump = gLastState_Pump;

		switch(pComp_Num1)
		{
		case 1:
			pLast_Fre_Pump_MAX = gComp_Data1;
			pComp_Num1 = 0;
			break;
		case 2:
			pLast_Fre_Pump_MIN = gComp_Data1;
			pComp_Num1 = 0;
			break;
		case 3:
			pLast_SVPump = gComp_Data1;
			pComp_Num1 = 0;
			break;
		case 4:
			if(gFlag_Pump_Fre == 0)
			{
				//DF800
				if(gComp_Data1 == 1)
				{
					pLast_State_Pump = 0;
				}
				else if(gComp_Data1 == 2)
				{
					pLast_State_Pump = 1;
				}
			}
			else if(gFlag_Pump_Fre == 1)
			{
				//DF900
				if(gComp_Data1 == 6)
				{
					pLast_State_Pump = 0;
				}
				else if(gComp_Data1 == 1)
				{
					pLast_State_Pump = 1;
				}
			}

			pComp_Num1 = 0;
			break;
		}

		if(gFlag_Pump_Fre == 0)  //DF800
		{
			//数据对比
			if(pNow_Fre_Pump_MAX != pLast_Fre_Pump_MAX)  //最大操作频率
			{
				if(gStateFinishMaster0206 < 3)
				{
					DRI_Master_02TX_Cmd06(105,pNow_Fre_Pump_MAX);  //DF800
					pComp_Num1 = 1;
					gStateFinishMaster0206++;
				}
			}
			else if(pNow_Fre_Pump_MIN != pLast_Fre_Pump_MIN)  //最小操作频率
			{
				if(gStateFinishMaster0206 < 3)
				{
					DRI_Master_02TX_Cmd06(106,pNow_Fre_Pump_MIN);  //DF800
					pComp_Num1 = 2;
					gStateFinishMaster0206++;
				}
			}
			else if(pNow_SVPump != pLast_SVPump)  //频率目标值
			{
				if(gStateFinishMaster0206 < 3)
				{
					DRI_Master_02TX_Cmd06(0x2001,gSV_Comp);  //DF800
					pComp_Num1 = 3;
					gStateFinishMaster0206++;
				}
			}
			else if(pNow_State_Pump != pLast_State_Pump)  //水泵运行状态
			{
				if(gStateFinishMaster0206 < 3)
				{
					if(gLastState_Pump == 0)  //水泵关闭
					{
						DRI_Master_02TX_Cmd06(0x2000,1);  //DF800
					}
					else if(gLastState_Pump == 1)  //水泵开启
					{
						DRI_Master_02TX_Cmd06(0x2000,2);  //DF800
					}
					pComp_Num1 = 4;
					gStateFinishMaster0206++;
				}
			}
			else
			{
				pCnt_Time++;
				if(pCnt_Time == 1)
				{
					DRI_Master_02TX_Cmd03(0x1b,1);  //作为主机发送给变频器  DF800
					pComp_Num1 = 0;
					gStateFinishMaster0203++;
				}
				else if(pCnt_Time == 2)  //发送03指令给D4306
				{
					gStateFinishMaster03++;
					DRI_Master_01TX_Cmd03();
				}
				else if(pCnt_Time == 3)  //发送16指令给D4306
				{
					gStateFinishMaster16++;
					DRI_Master_01TX_Cmd16();
					pCnt_Time = 0;
				}
			}
		}
		else if(gFlag_Pump_Fre == 1)  //DF900
		{
			//数据对比
			if(pNow_Fre_Pump_MAX != pLast_Fre_Pump_MAX)  //最大操作频率
			{
				if(gStateFinishMaster0206 < 3)
				{
					DRI_Master_02TX_Cmd06(0xf00c,pNow_Fre_Pump_MAX);  //DF900
					pComp_Num1 = 1;
					gStateFinishMaster0206++;
				}
			}
			else if(pNow_Fre_Pump_MIN != pLast_Fre_Pump_MIN)  //最小操作频率
			{
				if(gStateFinishMaster0206 < 3)
				{
					DRI_Master_02TX_Cmd06(0xf010,pNow_Fre_Pump_MIN);  //DF900
					pComp_Num1 = 2;
					gStateFinishMaster0206++;
				}
			}
			else if(pNow_SVPump != pLast_SVPump)  //频率目标值
			{
				if(gStateFinishMaster0206 < 3)
				{
					DRI_Master_02TX_Cmd06(0x1000,gSV_Comp);  //DF900
					pComp_Num1 = 3;
					gStateFinishMaster0206++;
				}
			}
			else if(pNow_State_Pump != pLast_State_Pump)  //水泵运行状态
			{
				if(gStateFinishMaster0206 < 3)
				{
					if(gLastState_Pump == 0)  //水泵关闭
					{
						DRI_Master_02TX_Cmd06(0x2000,6);  //DF900
					}
					else if(gLastState_Pump == 1)  //水泵开启
					{
						DRI_Master_02TX_Cmd06(0x2000,1);  //DF900
					}
					pComp_Num1 = 4;
					gStateFinishMaster0206++;
				}
			}
			else
			{
				pCnt_Time++;
				if(pCnt_Time == 1)
				{
					DRI_Master_02TX_Cmd03(0x8000,1);  //作为主机发送给变频器  DF900
					pComp_Num1 = 0;
					gStateFinishMaster0203++;
				}
				else if(pCnt_Time == 2)  //发送03指令给D4306
				{
					gStateFinishMaster03++;
					DRI_Master_01TX_Cmd03();
				}
				else if(pCnt_Time == 3)  //发送16指令给D4306
				{
					gStateFinishMaster16++;
					DRI_Master_01TX_Cmd16();
					pCnt_Time = 0;
				}
			}
		}

		if((gStateFinishMaster0203 >= 3) || (gStateFinishMaster0206 >= 3))  //变频器  03  06通讯异常
		{
			gAlaFlag_PumpCom1 = 1;
		}
		else
		{
			gAlaFlag_PumpCom1 = 0;
		}
	}
	else  //没有变频器
	{
		pCnt_Time++;
		if(pCnt_Time == 1)  //发送03指令给D4306
		{
			gStateFinishMaster03++;
			DRI_Master_01TX_Cmd03();
		}
		else if(pCnt_Time == 2)  //发送16指令给D4306
		{
			gStateFinishMaster16++;
			DRI_Master_01TX_Cmd16();
			pCnt_Time = 0;
		}
	}

	if((gStateFinishMaster03 >= 3) || (gStateFinishMaster16 >= 3))  //电子膨胀阀  03  16通讯异常
	{
		gAlaFlag_EEVCom = 1;
	}
	else
	{
		gAlaFlag_EEVCom = 0;
	}
}

/**
* @函数名	Task15
* @功能	    数字输入量采集  100ms
* @入口参数	无
* @返回值	无
*/
void Task15_CheakDI(void)
{
	static equState_t pState_RunSwitch = STATE_NO_CONFIG, pState_RunSwitch_Last;
	static equState_t pState_ResetSwitch, pState_ResetSwitch_Last;
	static equState_t pState_CycleSwitch, pState_CycleSwitch_Last;
	static equState_t pState_StopSwitch, pState_StopSwitch_Last;
	static uint8_t pCnt_RunSwitch_Cheak;
	static uint8_t pCnt_ResetSwitch_Cheak;
	static uint8_t pCnt_CycleSwitch_Cheak;
	static uint8_t pCnt_StopSwitch_Cheak;

	if(gLoading >= 100)
	{
		pState_RunSwitch = DRI_EQU_GetFunState(START_STOP_SWITCH);  //获取外部启停开关状态
	}
	if(pState_RunSwitch != STATE_NO_CONFIG)
	{
		if(DRI_EQU_GetFunTrigger(START_STOP_SWITCH) == LEVEL)  //边沿
		{
			if(pState_RunSwitch != pState_RunSwitch_Last)  //设备启停状态发生变化
			{
				pCnt_RunSwitch_Cheak++;
				if(pCnt_RunSwitch_Cheak > 2)
				{
					pCnt_RunSwitch_Cheak = 0;
					gState_Run =  pState_RunSwitch;
					pState_RunSwitch_Last = pState_RunSwitch;
				}
			}
			else  //设备启停状态无变化
			{
				pCnt_RunSwitch_Cheak = 0;
			}
		}
		else  //电平
		{
			if(pState_RunSwitch == pState_RunSwitch_Last)  //电平无变化
			{
				pCnt_RunSwitch_Cheak++;
				if(pCnt_RunSwitch_Cheak > 2)
				{
					pCnt_RunSwitch_Cheak = 0;
					gState_Run =  pState_RunSwitch;
				}
			}
			else  //电平产生变化
			{
				pCnt_RunSwitch_Cheak = 0;
				pState_RunSwitch_Last = pState_RunSwitch;
			}
		}
	}

	pState_ResetSwitch = DRI_EQU_GetFunState(RESET_ALARM);  //获取报警复位状态
	if(pState_ResetSwitch != STATE_NO_CONFIG)
	{
		if(pState_ResetSwitch != pState_ResetSwitch_Last)  //报警复位状态发生变化  边沿
		{
			pCnt_ResetSwitch_Cheak++;
			if(pCnt_ResetSwitch_Cheak > 2)
			{
				pCnt_ResetSwitch_Cheak = 0;
				if(pState_ResetSwitch == 1)  //上升沿
				{
					gAlarmReset =  pState_ResetSwitch;
				}
				pState_ResetSwitch_Last = pState_ResetSwitch;
			}
		}
		else  //报警复位状态无变化
		{
			pCnt_ResetSwitch_Cheak = 0;
		}
	}

	pState_CycleSwitch = DRI_EQU_GetFunState(CYCLE_SWITCHING);  //获取水路电磁阀输入状态
	if(pState_CycleSwitch != STATE_NO_CONFIG)
	{
		if(DRI_EQU_GetFunTrigger(CYCLE_SWITCHING) == LEVEL)  //边沿
		{
			if(pState_CycleSwitch != pState_CycleSwitch_Last)  //水路电磁阀状态发生变化
			{
				pCnt_CycleSwitch_Cheak++;
				if(pCnt_CycleSwitch_Cheak > 2)
				{
					pCnt_CycleSwitch_Cheak = 0;
					gEQUWaterin = pState_CycleSwitch_Last = pState_CycleSwitch;
				}
			}
			else
			{
				pCnt_CycleSwitch_Cheak = 0;
			}
		}
		else  //电平
		{
			if(pState_CycleSwitch == pState_CycleSwitch_Last)  //电平无变化
			{
				pCnt_CycleSwitch_Cheak++;
				if(pCnt_CycleSwitch_Cheak > 2)
				{
					pCnt_CycleSwitch_Cheak = 0;
					gEQUWaterin =  pState_CycleSwitch;
				}
			}
			else  //电平产生变化
			{
				pCnt_CycleSwitch_Cheak = 0;
				pState_CycleSwitch_Last = pState_CycleSwitch;
			}
		}
	}

	pState_StopSwitch = DRI_EQU_GetFunState(EMER_STOP_SWITCH);  //获取外部保护开关状态  电平
	if(pState_StopSwitch != STATE_NO_CONFIG)
	{
		if(pState_StopSwitch == pState_StopSwitch_Last)  //电平无变化
		{
			pCnt_StopSwitch_Cheak++;
			if(pCnt_StopSwitch_Cheak > 2)
			{
				pCnt_StopSwitch_Cheak = 0;
				if(pState_StopSwitch == 1)  //外部保护
				{
					//gAlaFlag_ESwitch1 = 1;
					gAlaFlag_EStop = 1;

					gState_Run = 0;
					gState_Pump = 0;
					gTime_StopPump = UP.Para.Time_StopDelayPump*5 + 1;  //取消本次延时停泵直接停泵

					task_structs[TASK_3].enable_flag = 0;  //程序控温
					task_structs[TASK_4].enable_flag = 0;  //气吹排液
					task_structs[TASK_6].enable_flag = 0;  //流量控制
					task_structs[TASK_7].enable_flag = 0;  //温度控制
					task_structs[TASK_8].enable_flag = 0;  //高温制冷阀控制
					task_structs[TASK_12].enable_flag = 0;  //温度补偿

					DRI_EQU_SetPinState(Equ_DO_Struct[U1],OFF);  //关闭输出1
					DRI_EQU_SetPinState(Equ_DO_Struct[U2],OFF);  //关闭输出2
					DRI_EQU_SetPinState(Equ_DO_Struct[U3],OFF);  //关闭输出3
					DRI_EQU_SetPinState(Equ_DO_Struct[U4],OFF);  //关闭输出4
					DRI_EQU_SetPinState(Equ_DO_Struct[K1],OFF);  //关闭输出5
					DRI_EQU_SetPinState(Equ_DO_Struct[K2],OFF);  //关闭输出6
					DRI_EQU_SetPinState(Equ_DO_Struct[K3],OFF);  //关闭输出7
				}
				else
				{
					gAlaFlag_EStop = 0;
					task_structs[TASK_3].enable_flag = 1;  //程序控温
					task_structs[TASK_4].enable_flag = 1;  //气吹排液
					task_structs[TASK_6].enable_flag = 1;  //流量控制
					task_structs[TASK_7].enable_flag = 1;  //温度控制
					task_structs[TASK_8].enable_flag = 1;  //高温制冷阀控制
					task_structs[TASK_12].enable_flag = 1;  //温度补偿
				}
			}
		}
		else  //电平产生变化
		{
			pCnt_StopSwitch_Cheak = 0;
			pState_StopSwitch_Last = pState_StopSwitch;
		}
	}
	else /* if no config */
	{
		gAlaFlag_EStop = 0;
	}
}


/**
* @函数名	Task16
* @功能	    数字输出量处理  100ms
* @入口参数	无
* @返回值	无
*/
void Task16_CheakDO(void)
{
	FUNC_Condition_To_DO(gState_Run == 1, RUN_STATE_OUT);	/* 运行状态 */

	FUNC_Condition_To_DO(gAlaFlag_FLT == 1, ALARM_OUT);  /* 报警状态 */

	FUNC_Condition_To_DO((gAlaFlag_Num != 0) && (gAlaFlag_FLT != 1), WARNINGS_OUT);  /* 警告状态 */

	FUNC_Condition_To_DO(gAlaFlag_Num != 0, ALL_ALARM_OUT);  /* 综合报警状态 */

	FUNC_Condition_To_DO((gAlaFlag_PumpMaint == 1) || (gAlaFlag_CompMaint == 1) || (gAlaFlag_FilterMaint == 1), ALL_MAINTAIN_OUT);  /* 维护提示状态 */

	FUNC_Condition_To_DO(UP.Para.Digital_IO_Dispose & 0x0001, DIGITAL_STATE_OUT);  /* 数字控制状态 */

	FUNC_Condition_To_DO((FP.Para.ES_DI_Contr == 1)&&(gAlaFlag_LL_DI == 1), DI_VALVE);  /* 水质控制使能 && 水质报警 */

	FUNC_Condition_To_DO((FP.Para.Type_CompNumber == 1)&&(gState_Comp2 == 1), COMP2);  /* 双机头模式 && 启动第2个压缩机*/

	FUNC_Condition_To_DO(gEQUWaterin == 1, CYCLE_SWITCHING_VALVE);  /* 内外循环阀*/

	//用户数字量输出1-KA1  报警
	if(DRI_EQU_GetFunState(SELECT_ALARM_OUT) != STATE_NO_CONFIG)  //报警输出配置
	{
		uint16_t temp_reg = 0;
		temp_reg = ((gAlaFlag_HighTemp & 0x01) << 0\
							| (gAlaFlag_LowTemp & 0x01) << 1\
							| (gAlaFlag_FacLowFlow & 0x01) << 2\
							| (gAlaFlag_RefHighPress & 0x01) << 3\
							| (gAlaFlag_RefLowPress & 0x01) << 4);

		FUNC_Condition_To_DO(UP.Para.Alarm_Out_Dispose1 && temp_reg, SELECT_ALARM_OUT);  /* 选择的报警*/
	}

	//用户数字量输出1-KA1 维护
	 if (DRI_EQU_GetFunState(SELECT_MAINTAIN_OUT) != STATE_NO_CONFIG)
	{
		 uint16_t temp_reg = 0;
		 temp_reg = ((gAlaFlag_PumpMaint & 0x01) << 0 \
		 							| (gAlaFlag_CompMaint & 0x01) << 2 \
		 							| (gAlaFlag_FilterMaint & 0x01) << 4);

		 FUNC_Condition_To_DO(UP.Para.Maintain_Out_Dispose && temp_reg, SELECT_MAINTAIN_OUT);  /* 选择的维护提示*/
	}

}
/**
* @函数名	Task17
* @功能	    FALSH测试
* @入口参数	无
* @返回值	无
*/
void task17_FlashTest(void)
{
	flash_test();
}
static void FUNC_Condition_To_DO(uint8_t candition, digitalOutType_t DO)
{
	if(candition)
	{
		DRI_EQU_SetFunState(DO, ON);  //开启数字量端口
	}
	else
	{
		DRI_EQU_SetFunState(DO, OFF);  //关闭数字量端口
	}
}
